<template>
	<div id="doctorWorkPage">
		<shyt-table
			ref="shytTable"
			:columns="columns"
			:data="tableData"
			:auto-resize="true"
			:keep-source="true"
			:pager-config="pageConfig"
			:toolbar-config="toolbarConfig"
			:edit-config="{ trigger: 'dbclick', mode: 'row', showStatus: true }"
			@page-change="pageChange"
		>
			<template #toolbar_buttons>
				<el-input
					v-model="doctorWorkInput"
					class="workName_input"
					placeholder="请输入查找的组名称"
					size="medium"
					clearable
				></el-input>
				<el-button type="primary" size="small" @click="handlerSeach">
					查询
				</el-button>
			</template>
			<template #edit="{ row }">
				<el-button type="text" size="small" @click="handlerWorkClick(row)">
					详情
				</el-button>
				<el-button type="text" size="small" @click="deldectDoctor(row)">
					删除
				</el-button>
			</template>
		</shyt-table>
		<doctorWorkDialog
			ref="doctorWorkDialog"
			:visible.sync="doctorWorkDialogVisible"
			:title="doctorWorkDialogTitle"
			:doctor-work="doctorWork"
		/>
	</div>
</template>
<script>
import { doctorWorkDelete, getDoctorWorkPageList } from '@/http/doctorWork'
import doctorWorkDialog from './components/doctorWorkDialog'
export default {
	name: 'DoctorWorkPage',
	components: { doctorWorkDialog },
	data() {
		return {
			orgList: [],
			doctorWork: {},
			doctorWorkDialogVisible: false,
			doctorWorkDialogTitle: '',
			loading: false,
			doctorWorkInput: null,
			//输入框校验
			rules: {},
			columns: [
				{
					field: 'workName',
					title: '工作组名称',
				},
				{
					field: 'orgName',
					title: '所属医院',
				},
				{
					field: 'deptName',
					title: '所属科室',
				},
				{
					field: 'doctorName',
					title: '所属医生',
				},
				{
					field: 'leadDoctorName',
					title: '领衔医生',
				},
				{
					title: '操作',
					slots: { default: 'edit' },
				},
			],
			tableData: [],
			// 按钮
			toolbarConfig: {
				slots: {
					buttons: 'toolbar_buttons',
				},
			},
			// 分页
			pageConfig: {
				currentPage: 1,
				pageSize: 10,
				pageSizes: [10, 20, 30, 50],
				total: 0,
				background: true,
				layouts: [
					'PrevPage',
					'JumpNumber',
					'NextPage',
					'FullJump',
					'Sizes',
					'Total',
				],
			},
		}
	},
	computed: {},
	created() {
		this.handlerSeach()
	},
	methods: {
		handlerWorkClick(row) {
			this.doctorWork = row
			this.doctorWorkDialogTitle = '新增工作组'
			this.doctorWorkDialogVisible = true
		},
		// 翻页事件
		pageChange({ currentPage, pageSize }) {
			this.pageConfig.currentPage = currentPage
			this.pageConfig.pageSize = pageSize
			this.handlerSeach()
		},
		// 删除
		deldectDoctor(row) {
			this.$confirm('同时移除该组下的医生，是否删除?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			})
				.then(() => {
					doctorWorkDelete(row).then(({ data }) => {
						if (data.head.code == 200) {
							this.$message({
								type: 'success',
								message: '删除成功!',
							})
							this.handlerSeach()
						}
					})
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除',
					})
				})
		},
		// 查询
		handlerSeach() {
			let param = {
				pageNum: this.pageConfig.currentPage,
				pageSize: this.pageConfig.pageSize,
				workName: this.doctorWorkInput,
			}
			getDoctorWorkPageList(param).then(({ data }) => {
				this.tableData = data.data.records
				this.pageConfig.total = data.data.total
			})
		},
	},
}
</script>

<style lang="scss" scoped>
.workName_input {
	width: 200px;
}
</style>
